< previous page page_682 next page >

Page 682
Instead, use code like this:
9f31265bb40b592b1929e18a47ab28e5.gif
For lngLoop = 0 To 10
   oRS.MoveFirst
   oConn.BeginTrans
   Do Until oRS.EOF
      oRS!szLast_nm = "GATES"
      oRS.Update
      oRS.MoveNext
   Loop
   oConn.CommitTrans
Next
The second example is faster because the values are typically cached by either the client or the database engine instead of written directly to the table. Then, when you commit the data, its written as a batch very quickly to the database.
Use SQL Instead of ADO Objects
Instead of using the ADO objects, you should use SQL directly because its faster. For example, suppose you have code that updates a single column, like this:
9f31265bb40b592b1929e18a47ab28e5.gif
For lngLoop = 0 To 10
   oRS.MoveFirst
   Do Until oRS.EOF
      oRS!szLast_nm = "GATES"
      oRS.Update
      oRS.MoveNext
   Loop
Next
You should change this code to use SQL instead. Heres an example:
9f31265bb40b592b1929e18a47ab28e5.gif
strSQL = "UPDATE tblEmployeesRollback "
strSQL = strSQL & "SET szLast_nm = 'GATES'"
For lngLoop = 0 To 10
   oConn.Execute strSQL
Next
This is faster because every time you perform the Update method on the ADO object, it has to gather the data in the buffer area for the recordset, convert it to a SQL statement (INSERT or UPDATE), and then send the SQL to the back end. You

 
< previous page page_682 next page >

If you like this book, buy it!